﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using weikebuluo.Model;
using weikebuluo.DAL;
using System.Data;

namespace weikebuluo.web.wechat.party
{
    public partial class join : System.Web.UI.Page
    {
        p_active_dal activedal = new p_active_dal();
        protected p_active_model activemodel = new p_active_model();
        p_join_dal joindal = new p_join_dal();
        protected p_join_model joinmodel = new p_join_model();
        protected DataTable dt = new DataTable();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(Request.QueryString["id"])) {
                activemodel = activedal.GetModel(int.Parse(Request.QueryString["id"].ToString()));
                dt = joindal.GetList("wxid='" + Request.QueryString["wxid"] + "'").Tables[0];
                if (dt.Rows.Count > 0)
                {
                    joinmodel = joindal.GetModel(int.Parse(dt.Rows[0]["join_id"].ToString()));
                }
            }

            switch (Request.Form["action"]) { 
                case "submit":
                    submit();
                    break;
            }
        }

        private void submit() {


            joinmodel.join_name = Request.Form["truename"];
            joinmodel.join_phone = Request.Form["telphone"];
            joinmodel.join_sex = Request.Form["sex"];
            joinmodel.active_id = int.Parse(Request.Form["id"].ToString());
            joinmodel.user_id = int.Parse(Request.Form["uid"]);
            joinmodel.wxid = Request.Form["wxid"];
            joindal.Add(joinmodel);
            Response.Write("<script Language=\"Javascript\">alert(\"活动参加成功！\")");
            Response.Write("</script>");
            Response.Write("<script Language=\"Javascript\">location.href=\"myorder.aspx?uid=" + Request.Form["uid"] + "&wxid=" + Request.Form["wxid"] + "\";");
            Response.Write("</script>");
            Response.End();

        }
    }
}